package com.zjs.server.comsumer.contoeller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zjs.server.comsumer.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestContorller {

    @Autowired
    private TestService testService;

    @GetMapping(value = "/f1")
    @HystrixCommand(fallbackMethod = "test11")
    public String test1(){
       return testService.test1();
    }

    @GetMapping(value = "/f2/{name}")
    @HystrixCommand(fallbackMethod = "test22")
    public String test2(@PathVariable(value = "name") String name){
        return testService.test2(name);
    }

    @GetMapping(value = "/timeOut/{s}")
    @HystrixCommand(fallbackMethod = "time")
    public String timeOut(@PathVariable(value = "s") int s){
        return testService.timeOut(s);
    }

    @GetMapping(value = "/timeOut1/{s}")
    @HystrixCommand(fallbackMethod = "time1")
    public String timeOut1(@PathVariable(value = "s") int s){
        return testService.timeOut1(s);
    }

    public String test22(String name){
        return "test2方法被熔断";
    }
    public String test11(){
        return "test1方法被熔断";
    }
    public String time( int s ){
        return "time方法被熔断了";
    }

    public String time1( int s ){
        return "time方法被熔断了";
    }

}
